class Post < ActiveRecord::Base
  has_many :comments 
  
  validates_presence_of :title, :body
  
  named_scope :recent, :limit => 3, :conditions => "created_at > '#{1.day.ago.to_s(:db)}'", :order => "created_at desc"
  named_scope :last_five, :limit => 5, :order => "created_at desc"
  
  def set_page(post)
    post.page = ((post.id - 1)/5) + 1
    post.save
  end

end
